// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using System;
using System.Linq;
using NUnit.Framework;
using ValidationAspects;
using ValidationAspects.Exceptions;

namespace TestValidationAspects
{
	[TestFixture]
	public class TestValidationResult
	{
		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_Constructor_throws_for_null_param()
		{
			new ValidationResult(null);
		}

		[Test]
		public void Test_IsValid()
		{
			Assert.IsTrue(new ValidationResult().IsValid);
			Assert.IsFalse(new ValidationResult(new ValidationException()).IsValid);
		}

		[Test]
		public void Test_Messages()
		{
			Assert.AreEqual(0, new ValidationResult().Messages.Count());

			string[] messages = new ValidationResult(new ValidationContextException(new[] {new ValidationException("1"), new ValidationException("2")})).Messages.ToArray();
			Assert.AreEqual(2, messages.Length);
			Assert.AreEqual("1", messages[0]);
			Assert.AreEqual("2", messages[1]);
		}

		[Test]
		public void Test_ValidationException()
		{
			Assert.IsNull(new ValidationResult().ValidationException);

			ValidationException exception = new ValidationException();
			Assert.AreSame(exception, new ValidationResult(exception).ValidationException);
		}
	}
}